package com.frx.leetoffer.dayone;

/**
 * Created with IDEA
 *
 * @description 二维数组的查找
 * 给定一个二维数组，其每一行从左到右递增排序，从上到下也是递增排序。给定一个数，判断这个数是否在该二维数组中
 * [
     [1,   4,  7, 11, 15],
     [2,   5,  8, 12, 19],
     [3,   6,  9, 16, 22],
     [10, 13, 14, 17, 24],
     [18, 21, 23, 26, 30]
* ]
    Given target = 5, return true.
    Given target = 20, return false.
 * @author: xrf
 * @Date: 2019/5/7
 * @Time: 16:48
 */
public class FindArray {
    public static void main(String[] args){



    }

    public static boolean find(int target, int [][] array) {
        int len = array[0].length-1;
        int i = 0;
        while((len >= 0)&& (i < array.length)){
            if(array[i][len] > target){
                len--;
            }else if(array[i][len] < target){
                i++;
            }else{
                return true;
            }
        }
        return false;
    }
}
